﻿namespace ReactiveGraph.Core
{
    public class EventSource
    {
        public IReactiveNode Node { get; private set; }
        public IProperty Property { get; private set; }
        public object PropertyTriggerValue { get; private set; }
        public IReactiveNode ParentNode { get; private set; }
        public NodePath Path { get; private set; }

        public static EventSource PropertyChanged(IReactiveNode node, IProperty property, object value)
        {
            return new EventSource
                       {
                           Node = node,
                           Property = property,
                           PropertyTriggerValue = value,
                           Path = NodePath.WithNodes(node)
                       };
        }

        public static EventSource NodeAdded(IReactiveNode added, IReactiveNode toParent)
        {
            return new EventSource
                       {
                           Node = added,
                           ParentNode = toParent,
                           Path = NodePath.WithNodes(toParent, added)
                       };
        }

        public static EventSource NodeRemoved(IReactiveNode removed, IReactiveNode fromParent)
        {
            return new EventSource
                       {
                           Node = removed,
                           ParentNode = fromParent,
                           Path = NodePath.WithNodes(fromParent, removed)
                       };
        }

        public static EventSource Wrap(EventSource source, IReactiveNode node)
        {
            return new EventSource
                       {
                           Node = source.Node,
                           ParentNode = source.ParentNode,
                           Property = source.Property,
                           PropertyTriggerValue = source.PropertyTriggerValue,
                           Path = source.Path.Concat(node)
                       };
        }
    }
}